package com.at.util;

import org.springframework.util.DigestUtils;

/**
 * @author : code1997
 * @date :2020-09-2020/9/27 21:33
 */
public class MD5Util {
    public static String md5(String text){
        //加密后的字符串
        String encodeStr="";
        try {
            encodeStr= DigestUtils.md5DigestAsHex((text).getBytes());
            System.out.println("MD5加密后的字符串为:encodeStr="+encodeStr);
        }catch (Exception e){
            e.printStackTrace();
        }
        return encodeStr;
    }

    public static boolean verify(String text, String md5) throws Exception {
        //根据传入的密钥进行验证
        String md5Text = md5(text);
        return md5Text.equalsIgnoreCase(md5);
    }

    public static void main(String[] args) throws Exception {
        String admin = md5("admin");
        System.out.println(admin);
    }
}
